package com.heima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.mapper.OrderMapper;
import com.heima.pojo.Order;
import com.heima.pojo.dto.OrderPageDto;
import com.heima.pojo.vo.OrderPageVo;
import com.heima.pojo.vo.SkuVo;
import com.heima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 订单搜索
     * @param dto
     * @return
     */
    @Override
    public OrderPageVo pageQuery(OrderPageDto dto) {
        dto.check();
        PageHelper.startPage(dto.getPageIndex(),dto.getPageSize());
        Page<Order> orders =  orderMapper.pageQuery(dto);
        OrderPageVo orderPageVo = new OrderPageVo();
        orderPageVo.setCurrentPageRecords(orders);
        orderPageVo.setPageIndex(dto.getPageIndex());
        orderPageVo.setPageSize(dto.getPageSize());
        orderPageVo.setTotalPage(orders.getPages());
        orderPageVo.setTotalCount(orders.getTotal());
        return orderPageVo;
    }

    /**
     * 补货数量统计
     * @param innerCode
     * @param start
     * @param end
     * @return
     */
    @Override
    public List<SkuVo> skuCollect(String innerCode, Date start, Date end) {
        return orderMapper.skuCollect(innerCode,start,end);
    }
}
